#define _CRT_SECURE_NO_WARNINGS 1

#include<vector>
#include<iostream>

using namespace std;

bool canPlaceFlowers(vector<int>& flowerbed, int n) {
    vector<bool> sta(flowerbed.size(), true);
    for (int i = 0; i < flowerbed.size(); i++)
    {
        if (flowerbed[i] == 1)
        {
            sta[i] = false;
            if (i - 1 >= 0)
                sta[i - 1] = false;
            if (i + 1 < flowerbed.size())
                sta[i + 1] = false;
        }
    }
    for (int i = 0; i < flowerbed.size(); i++)
    {
        if (sta[i] == true)
        {
            n--;
            sta[i] = false;
            if (i - 1 >= 0)
                sta[i - 1] = false;
            if (i + 1 < flowerbed.size())
                sta[i + 1] = false;
        }
    }
    return n <= 0;
}
int main()
{
    vector<int> v = { 1,0,0,0,1 };
    canPlaceFlowers(v, 2);
    return 0;
}